home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / demos / retinarave / include / pp-decrunch.s < prev    next >
Text File  |  1980-01-03  |  2KB  |  107 lines

  1.  
  2. ;====================================================
  3. ;
  4. ;        POWERPACKER DECRUNCH ROUTINE
  5. ;
  6. ; a3 -> destination, a0 -> longword after crunched,
  7. ; a5 -> ptr to eff., a6 -> decr.col
  8. ;
  9. ; destroys a0-a6 and d0-d7
  10. ;====================================================
  11.  
  12. Unpack:
  13.  
  14.     moveq #3,d6
  15.     moveq #7,d7
  16.     moveq #1,d5
  17.     move.l a3,a2            ; remember start of file
  18.     move.l -(a0),d1            ; get file length and empty bits
  19.     tst.b d1
  20.     beq.s NoEmptyBits
  21.     bsr.s ReadBit        ; this will always get the next long (D5 = 1)
  22.     subq.b #1,d1
  23.     lsr.l d1,d5            ; get rid of empty bits
  24. NoEmptyBits:
  25.     lsr.l #8,d1
  26.     add.l d1,a3            ; a3 = endfile
  27. ****    move.l d1,length
  28.  
  29. LoopCheckCrunch:
  30.     bsr.s ReadBit            ; check if crunch or normal
  31.     bcs.s CrunchedBytes
  32. NormalBytes:
  33.     moveq #0,d2
  34. Read2BitsRow:
  35.     moveq #1,d0
  36.     bsr.s ReadD1
  37.     add.w d1,d2
  38.     cmp.w d6,d1
  39.     beq.s Read2BitsRow
  40. ReadNormalByte:
  41.     moveq #7,d0
  42.     bsr.s ReadD1
  43.     move.b d1,-(a3)
  44.     dbf d2,ReadNormalByte
  45.     cmp.l a3,a2
  46.     bcs.s CrunchedBytes
  47.     rts
  48. ReadBit:
  49.     lsr.l #1,d5        ; this will also set X if d5 becomes zero
  50.     beq.s GetNextLong
  51.     rts
  52. GetNextLong:
  53.     move.l -(a0),d5
  54.     roxr.l #1,d5            ; X-bit set by lsr above
  55.     rts
  56. ReadD1sub:
  57.     subq.w #1,d0
  58. ReadD1:
  59.     moveq #0,d1
  60. ReadBits:
  61.     lsr.l #1,d5        ; this will also set X if d5 becomes zero
  62.     beq.s GetNext
  63. RotX:
  64.     roxl.l #1,d1
  65.     dbf d0,ReadBits
  66.     rts
  67. GetNext:
  68.     move.l -(a0),d5
  69.     roxr.l #1,d5            ; X-bit set by lsr above
  70.     bra.s RotX
  71. CrunchedBytes:
  72.     moveq #1,d0
  73.     bsr.s ReadD1            ; read code
  74.     moveq #0,d0
  75.     move.b 0(a5,d1.w),d0        ; get number of bits of offset
  76.     move.w d1,d2            ; d2 = code = length-2
  77.     cmp.w d6,d2        ; if d2 = 3 check offset bit and read length
  78.     bne.s ReadOffset
  79.     bsr.s ReadBit            ; read offset bit (long/short)
  80.     bcs.s LongBlockOffset
  81.     moveq #7,d0
  82. LongBlockOffset:
  83.     bsr.s ReadD1sub
  84.     move.w d1,d3            ; d3 = offset
  85. Read3BitsRow:
  86.     moveq #2,d0
  87.     bsr.s ReadD1
  88.     add.w d1,d2            ; d2 = length-1
  89.     cmp.w d7,d1            ; cmp with #7
  90.     beq.s Read3BitsRow
  91.     bra.s DecrunchBlock
  92. ReadOffset:
  93.     bsr.s ReadD1sub            ; read offset
  94.     move.w d1,d3            ; d3 = offset
  95. DecrunchBlock:
  96.     addq.w #1,d2
  97. DecrunchBlockLoop:
  98.     move.b 0(a3,d3.w),-(a3)
  99.     dbf d2,DecrunchBlockLoop
  100. EndOfLoop:
  101.     move.w a3,(a6)            ; flash register bits
  102.     cmp.l a3,a2
  103.     bcs LoopCheckCrunch
  104.  
  105.     rts
  106.  
  107.